﻿using AdinZ.DB;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;


/**
* @Author: AdinZ
* @Q  Q : 1454269
* @Email:adinz@adinz.com
* @Created: 2014/4/19 12:30:34
*
* */
namespace Novel.Sys.Dal
{
    public class novel_checkin
    {
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Add(Model.novel_checkin model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("INSERT INTO [novel_checkin] ([uid], [time], [award],[mark]) VALUES (");
            strSql.Append("@uid,@time,@award,@mark");
            strSql.Append(");select @@IDENTITY");
            SqlParameter[] parameters = {
                    new SqlParameter("@uid", SqlDbType.Int),
                    new SqlParameter("@time", SqlDbType.DateTime),
                    new SqlParameter("@award", SqlDbType.Float),
                    new SqlParameter("@mark", SqlDbType.NVarChar)};
            parameters[0].Value = model.Uid;
            parameters[1].Value = model.Time;
            parameters[2].Value = model.Award;
            parameters[3].Value = model.Mark;

            object obj = DbHelpers.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="Name"></param>
        /// <param name="Passwd"></param>
        /// <returns></returns>
        public bool Exists(int Uid, string mark)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from [novel_checkin]");
            strSql.Append(" where uid=@uid and mark=@mark");
            SqlParameter[] parameters = {
                    new SqlParameter("@uid", SqlDbType.Int),
                    new SqlParameter("@mark", SqlDbType.NVarChar)};
            parameters[0].Value = Uid;
            parameters[1].Value = mark;
            return DbHelpers.Exists(strSql.ToString(), parameters);
        }

        public int GetCount(int Uid)
        {
            string sql = "select count(1) from [novel_checkin] where [uid]='" + Uid+"'";
            object obj = DbHelpers.GetSingle(sql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }

    }
}
